package com.leiyuee.Thread;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.*;

/**
 * @Author : Yu_Lei
 * @create 2024/3/11
 */
public class Other {

    public void executorService() {
        ExecutorService poll1 = Executors.newFixedThreadPool(2);
        poll1.execute(()->{
            System.out.println("ExecutorService--1");
        });

        ThreadPoolExecutor pool2 = new ThreadPoolExecutor(2, 10, 0, TimeUnit.SECONDS
                , new LinkedBlockingDeque<>(), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        pool2.submit(()->{
            System.out.println("pool--2");
        });

        CompletableFuture<String> supplyAsync = CompletableFuture.supplyAsync(() -> {
            System.out.println("completableFuture");
            return "ok";
        });

        ThreadGroup group = new ThreadGroup("group");
        new Thread(group,()->{
            System.out.println("group1");
        },"g1").start();

        new Thread(group,()->{
            System.out.println("group2");
        },"g2").start();

        FutureTask<String> task = new FutureTask<>(() -> {
            System.out.println("futureTask");
            return "task";
        });
        new Thread(task).start();

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("timeTask");
            }
        },0,1000);

        ForkJoinPool forkJoinPool = new ForkJoinPool();
        forkJoinPool.execute(()->{
            System.out.println("forkJoin");
        });

        List<String> list = new ArrayList<>();
        list.parallelStream().forEach(System.out::println);

    }
}
